package com.hfh.work;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author hfh
 * @Date 2022 09 15 16 53
 **/
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerDemo sd = new ServerDemo();
        ServerSocket ss = new ServerSocket(9999);
        Socket s = ss.accept();
        sd.server(s);
        s.close();
        ss.close();


    }
    public void server(Socket s) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        PrintWriter pw = new PrintWriter(s.getOutputStream());
        Scanner sc = new Scanner(System.in);

        while (true){
            String str = br.readLine();
            System.out.println(str);
            if ("exit".equals(str)){
                break;
            }

            String msg = sc.next();
            pw.println(msg);
            pw.flush();
        }
    }
}
